package com.ruoyi.airspaceFlight.controller;

import com.ruoyi.airspaceFlight.dto.req.AirspaceSetReqDto;
import com.ruoyi.airspaceFlight.dto.req.StatusDto;
import com.ruoyi.airspaceFlight.dto.req.TAirspaceSettingsDto;
import com.ruoyi.airspaceFlight.dto.resp.AirspaceSetRespDto;
import com.ruoyi.airspaceFlight.mapper.TAirspaceTypeMapper;
import com.ruoyi.airspaceFlight.service.TAirspaceSettingsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 空域设置信息Controller
 *
 * @author ruoyi
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/settings")
public class TAirspaceSettingsController extends BaseController
{
    @Autowired
    private TAirspaceSettingsService tAirspaceSettingsService;

    @Autowired
    private TAirspaceTypeMapper tAirspaceTypeMapper;


    /**
     * 空域类型下拉框
     */
    @GetMapping("/getAirspaceType")
    public AjaxResult getAirspaceType()
    {
        return AjaxResult.success(tAirspaceTypeMapper.getTAirspaceTypeBox());
    }


    /**
     * 空域查询
     */
//    @RequiresPermissions("system:settings:list")
    @GetMapping("/getAirspace/{airTypeIds}")
    public AjaxResult getAirspace(@PathVariable List<String> airTypeIds)
    {
        return AjaxResult.success(tAirspaceSettingsService.getAirspace(airTypeIds));
    }

    /**
     * 查询空域设置信息列表
     */
//    @RequiresPermissions("system:settings:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody AirspaceSetReqDto airspaceSetReqDto)
    {
        startPage();
        List<AirspaceSetRespDto> list = tAirspaceSettingsService.selectTAirspaceSettingsList(airspaceSetReqDto);
        return getDataTable(list);
    }

    /**
     * 获取空域设置信息详细信息
     */
//    @RequiresPermissions("system:settings:query")
    @GetMapping(value = "/{airspaceId}")
    public AjaxResult getInfo(@PathVariable("airspaceId") String airspaceId)
    {
        return AjaxResult.success(tAirspaceSettingsService.selectTAirspaceSettingsByAirspaceId(airspaceId));
    }

    /**
     * 新增空域设置信息
     */
//    @RequiresPermissions("system:settings:add")
//    @Log(title = "空域设置信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TAirspaceSettingsDto tAirspaceSettingsDto)
    {
        return tAirspaceSettingsService.insertTAirspaceSettings(tAirspaceSettingsDto);
    }

    /**
     * 修改空域设置信息
     */
//    @RequiresPermissions("system:settings:edit")
//    @Log(title = "空域设置信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TAirspaceSettingsDto tAirspaceSettingsDto)
    {
        return tAirspaceSettingsService.updateTAirspaceSettings(tAirspaceSettingsDto);
    }

    /**
     * 停用/启用空域设置信息  0-生效中 1-待生效 2-已停用 3-已到期
     */
//    @RequiresPermissions("system:settings:onOff")
//    @Log(title = "空域设置信息", businessType = BusinessType.UPDATE)
    @PutMapping("/onOff")
    public AjaxResult onOff(@RequestBody StatusDto statusDto)
    {
        return toAjax(tAirspaceSettingsService.onOffTAirspaceSettings(statusDto));
    }

    /**
     * 删除空域设置信息
     */
//    @RequiresPermissions("system:settings:remove")
//    @Log(title = "空域设置信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{airspaceId}")
    public AjaxResult remove(@PathVariable String airspaceId)
    {
        return toAjax(tAirspaceSettingsService.deleteTAirspaceSettingsByAirspaceId(airspaceId));
    }
}
